package com.hbnu.iostream;

import java.io.IOException;
import java.io.PipedInputStream;

public class Receive implements Runnable{

    PipedInputStream pipedInputStream;

    public Receive() {
        pipedInputStream = new PipedInputStream();
    }

    @Override
    public void run(){
        byte[] bytes = new byte[1024];

        try {
            int length = pipedInputStream.read(bytes);
            System.out.println(new String(bytes,0,length));

        }
        catch (IOException e) {
            throw new RuntimeException(e);
        }
        finally {
            try {
                pipedInputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
